import {useState} from 'react'
import { Redirect } from 'react-router-dom';
import { connect } from 'react-redux'
import './index.scss'

const Cart = (props) =>{
  const {cartlist,setCartlist} = useState({})
  console.log(props);
  const goItem=()=>{
    props.history.push("/item")
  }
  return (
    <div className="cart_com">
    {localStorage.getItem("token")!==null?<div>购物车
      <div className="cancel" onClick={goItem}>取消</div>
       <ul>
         {cartlist.map(item=> <li key={item.id} >
          <div className="cart_img"><img src={item.img} alt="" /></div>
           <div>{item.name}-{item.price}-{item.num}</div>
           </li>)}
       </ul>
    </div>:<Redirect to="/login" />}
    </div>
    )

}

export default connect(state=>({cartlist:state.cartlist}))(Cart)